package chap3_5;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;

/**
 * @author https://gitee.com/W_Jun
 * @date 2021-12-13 17:26
 * @Description 字符流写数据的5种方式
 */
public class OutputStreamWriterDemo {
    public static void main(String[] args) throws IOException {
        OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream("chapter03-字符流\\osw.txt"));
        //void write(int c)：写一个字符
        osw.write(97);
        //void flush()：刷新流
        osw.flush();
        //释放资源
        //osw.close();
        System.out.println("-------");

        //void write(char[] cbuf)：写一个字符数组
        char[] chs = {'a', 'b', 'c', 'd'};
        osw.write(chs);
        osw.flush();
        //osw.close();
        System.out.println("-------");

        //void write(char[] cbuf, int off, int len)：写入字符数组的一部分
        osw.write(chs, 0, chs.length);
        osw.flush();
        //osw.close();
        System.out.println("-------");

        //void write(String str)：写一个字符数串
        osw.write("abcde");
        osw.flush();
        //osw.close();

        //void write(String str, int off, int len)：写一个字符数串的一部分
        osw.write("abcde", 0, "abcde".length());
        osw.flush();
        osw.close();
    }
}
